<template>
    <view class="dynamicModel-list-v">
        <view class="head-warp com-dropdown">
            <u-dropdown class="u-dropdown" ref="uDropdown" @close="closeData">
                <u-dropdown-item title="排序">
                    <view class="dropdown-slot-content">
                        <view class="dropdown-slot-content-main">
                            <u-cell-group>
                                <u-cell-item @click="cellClick(item)" :arrow="false" :title="item.label"
									 v-for="(item, index) in sortOptions" :key="index" :title-style="{color: sortValue == item.value ? '#2979ff' : '#606266' }">
                                    <u-icon v-if="sortValue == item.value" name="checkbox-mark" color="#2979ff" size="32"></u-icon>
                                </u-cell-item>
                            </u-cell-group>
                        </view>
                    </view>
                </u-dropdown-item>
                <u-dropdown-item title="筛选" >
                    <view class="dropdown-slot-content">
                        <view class="dropdown-slot-content-main search-main">
                            <view class="u-p-l-32 u-p-r-32 search-form">
								<u-form :model="searchForm" ref="searchForm" :errorType="['toast']" label-position="left" label-width="150">
                                    <u-form-item label="公司名称" prop="companyname">
										<u-input v-model="searchForm.companyname" placeholder="请输入公司名称" />
                                    </u-form-item>
                                    <u-form-item label="职称" prop="companytitle">
										<u-input v-model="searchForm.companytitle" placeholder="请输入职称" />
                                    </u-form-item>
                                    <u-form-item label="建档时间" prop="creatortime">
										<jnpf-date-range  v-model="searchForm.creatortime" />
                                    </u-form-item>
                                    <u-form-item label="名字" prop="username">
										<u-input v-model="searchForm.username" placeholder="请输入名字" />
                                    </u-form-item>
                                    <u-form-item label="性别" prop="gender">
										<jnpf-select v-model="searchForm.gender" :options="genderOptions" :props="genderProps" placeholder="请选择性别"/>
                                    </u-form-item>
                                    <u-form-item label="身份证号" prop="cardid">
										<u-input v-model="searchForm.cardid" placeholder="请输入身份证号" />
                                    </u-form-item>
                                    <u-form-item label="学历" prop="education">
										<jnpf-select v-model="searchForm.education" :options="educationOptions" :props="educationProps" placeholder="请选择学历"/>
                                    </u-form-item>
                                    <u-form-item label="健康状况" prop="health">
										<jnpf-select v-model="searchForm.health" :options="healthOptions" :props="healthProps" placeholder="请选择健康状况"/>
                                    </u-form-item>
                                    <u-form-item label="籍贯" prop="nativeplace">
										<u-input v-model="searchForm.nativeplace" placeholder="请输入籍贯" />
                                    </u-form-item>
                                    <u-form-item label="家庭住址" prop="homeaddress">
										<u-input v-model="searchForm.homeaddress" placeholder="请输入家庭住址" />
                                    </u-form-item>
                                    <u-form-item label="入厂时间" prop="jointime">
										<jnpf-date-range  v-model="searchForm.jointime" />
                                    </u-form-item>
                                    <u-form-item label="从事工种" prop="typework">
										<u-input v-model="searchForm.typework" placeholder="请输入从事工种" />
                                    </u-form-item>
								</u-form>
                            </view>
							<view class="buttom-actions">
							  <u-button class="buttom-btn" @click="reset">重置</u-button>
							  <u-button class="buttom-btn" type="primary" @click="closeDropdown">检索</u-button>
							</view>
							<view class="dropdown-slot-bg" @click="$refs.uDropdown.close()"></view>
                        </view>
                    </view>
                </u-dropdown-item>
            </u-dropdown>
        </view>
		<view class="list-warp">
			<mescroll-uni ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :fixed="false" :down="downOption" :up="upOption">
				<view class="list">
					<view class="list-box" v-for="(item, index) in list" :key="item.prop">
						<u-swipe-action :index="index" @click="handleClick" @open="open" :options="options" @content-click="goDetail(item.id,item.flowState)">
                        <view class="item">
                        <view class="item-cell u-line-1" >
                            <text>公司名称：</text>
                            <text>{{item.companyname}}</text>
                        </view>
                        <view class="item-cell u-line-1" >
                            <text>职称：</text>
                            <text>{{item.companytitle}}</text>
                        </view>
                        <view class="item-cell u-line-1" >
                            <text>建档时间：</text>
                            <text>{{item.creatortime}}</text>
                        </view>
                        <view class="item-cell u-line-1" >
                            <text>名字：</text>
                            <text>{{item.username}}</text>
                        </view>
                        <view class="item-cell u-line-1" >
                            <text>性别：</text>
                            <text>{{item.gender | dynamicText(genderOptions)}}</text>
                        </view>
                        <view class="item-cell u-line-1" >
                            <text>身份证号：</text>
                            <text>{{item.cardid}}</text>
                        </view>
                        <view class="item-cell u-line-1" >
                            <text>学历：</text>
                            <text>{{item.education | dynamicText(educationOptions)}}</text>
                        </view>
                        <view class="item-cell u-line-1" >
                            <text>健康状况：</text>
                            <text>{{item.health | dynamicText(healthOptions)}}</text>
                        </view>
                        <view class="item-cell u-line-1" >
                            <text>籍贯：</text>
                            <text>{{item.nativeplace}}</text>
                        </view>
                        <view class="item-cell u-line-1" >
                            <text>家庭住址：</text>
                            <text>{{item.homeaddress}}</text>
                        </view>
                        <view class="item-cell u-line-1" >
                            <text>入厂时间：</text>
                            <text>{{item.jointime}}</text>
                        </view>
                        <view class="item-cell u-line-1" >
                            <text>从事工种：</text>
                            <text>{{item.typework}}</text>
                        </view>
                        </view>
						</u-swipe-action>
					</view>
				</view>
			</mescroll-uni>
		</view>
        <view class="com-addBtn" @click="addPage()" >
            <u-icon name="plus" size="60" color="#fff" />
        </view>
    </view>
</template>

<script>
    import resources from '@/libs/resources.js'
    import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
    import {
        getDictionaryDataSelector,
        getDataInterfaceRes
    } from '@/api/common'
    import request from '@/utils/request'
    export default {
		mixins: [MescrollMixin],
        data() {
            return {
                sortValue: '',
                searchForm: {
                    companyname:undefined,
                    companytitle:undefined,
                    creatortime:undefined,
                    username:undefined,
                    gender:undefined,
                    cardid:undefined,
                    education:undefined,
                    health:undefined,
                    nativeplace:undefined,
                    homeaddress:undefined,
                    jointime:undefined,
                    typework:undefined,
                },
                downOption: {
                    use: true,
                    auto: false
                },
                upOption: {
                    page: {
                        num: 0,
                        size: 20,
                        time: null,
                    },
                    empty: {
                        use: true,
                        icon: resources.message.nodata,
                        tip: "暂无数据",
                        fixed: true,
                        top: "300rpx",
                        zIndex: 5,
                    },
                    textNoMore: '没有更多数据',
                    toTop: {
                        bottom: 250
                    }
                },
                genderOptions:[{"fullName":"男","id":"1"},{"fullName":"女","id":"2"}],
                genderProps:{"label":"fullName","value":"id"},
                educationOptions:[{"fullName":"选项一","id":"1"},{"fullName":"选项二","id":"2"}],
                educationProps:{"label":"fullName","value":"id"},
                healthOptions:[{"fullName":"健康","id":"1"},{"fullName":"不健康","id":"2"}],
                healthProps:{"label":"fullName","value":"id"},
				list: [],
				listQuery: {
				    sort: 'desc',
				    sidx: '',
				    keyword: '',
				    json: ''
				},
				options: [
                    {
                        text: '删除',
                        style: {
                            backgroundColor: '#dd524d'
                        }
                    },
				],
				sortOptions:[
				    {
				        label: '公司名称降序',
				        sidx: 'companyname',
				        value: 'companynamedesc',
				        sort: 'desc'
				    },
				    {
				        label: '公司名称升序',
				        sidx: 'companyname',
				        value: 'companynameasc',
				        sort: 'asc'
				    },
				    {
				        label: '职称降序',
				        sidx: 'companytitle',
				        value: 'companytitledesc',
				        sort: 'desc'
				    },
				    {
				        label: '职称升序',
				        sidx: 'companytitle',
				        value: 'companytitleasc',
				        sort: 'asc'
				    },
				    {
				        label: '建档时间降序',
				        sidx: 'creatortime',
				        value: 'creatortimedesc',
				        sort: 'desc'
				    },
				    {
				        label: '建档时间升序',
				        sidx: 'creatortime',
				        value: 'creatortimeasc',
				        sort: 'asc'
				    },
				    {
				        label: '名字降序',
				        sidx: 'username',
				        value: 'usernamedesc',
				        sort: 'desc'
				    },
				    {
				        label: '名字升序',
				        sidx: 'username',
				        value: 'usernameasc',
				        sort: 'asc'
				    },
				    {
				        label: '性别降序',
				        sidx: 'gender',
				        value: 'genderdesc',
				        sort: 'desc'
				    },
				    {
				        label: '性别升序',
				        sidx: 'gender',
				        value: 'genderasc',
				        sort: 'asc'
				    },
				    {
				        label: '身份证号降序',
				        sidx: 'cardid',
				        value: 'cardiddesc',
				        sort: 'desc'
				    },
				    {
				        label: '身份证号升序',
				        sidx: 'cardid',
				        value: 'cardidasc',
				        sort: 'asc'
				    },
				    {
				        label: '学历降序',
				        sidx: 'education',
				        value: 'educationdesc',
				        sort: 'desc'
				    },
				    {
				        label: '学历升序',
				        sidx: 'education',
				        value: 'educationasc',
				        sort: 'asc'
				    },
				    {
				        label: '健康状况降序',
				        sidx: 'health',
				        value: 'healthdesc',
				        sort: 'desc'
				    },
				    {
				        label: '健康状况升序',
				        sidx: 'health',
				        value: 'healthasc',
				        sort: 'asc'
				    },
				    {
				        label: '籍贯降序',
				        sidx: 'nativeplace',
				        value: 'nativeplacedesc',
				        sort: 'desc'
				    },
				    {
				        label: '籍贯升序',
				        sidx: 'nativeplace',
				        value: 'nativeplaceasc',
				        sort: 'asc'
				    },
				    {
				        label: '家庭住址降序',
				        sidx: 'homeaddress',
				        value: 'homeaddressdesc',
				        sort: 'desc'
				    },
				    {
				        label: '家庭住址升序',
				        sidx: 'homeaddress',
				        value: 'homeaddressasc',
				        sort: 'asc'
				    },
				    {
				        label: '入厂时间降序',
				        sidx: 'jointime',
				        value: 'jointimedesc',
				        sort: 'desc'
				    },
				    {
				        label: '入厂时间升序',
				        sidx: 'jointime',
				        value: 'jointimeasc',
				        sort: 'asc'
				    },
				    {
				        label: '从事工种降序',
				        sidx: 'typework',
				        value: 'typeworkdesc',
				        sort: 'desc'
				    },
				    {
				        label: '从事工种升序',
				        sidx: 'typework',
				        value: 'typeworkasc',
				        sort: 'asc'
				    },
				],
                menuId:'',
            }
        },
        onLoad(e){
			this.menuId = e.menuId
            uni.$on('refresh', () => {
                this.list = [];
                this.mescroll.resetUpScroll();
            })
            this.dataAll()
        },
        onUnload() {
            uni.$off('refresh')
        },
        methods:{
			dataAll(){
			},
			closeData(e){
			    if(e==1){
			        // this.reset()
			    }
			},
            upCallback(page) {
    //             for(let i in this.searchForm){
				// 	if(!this.searchForm[i]){
				// 		delete this.searchForm[i]
				// 	}
				// }
                const query = {
                    currentPage: page.num,
                    pageSize: page.size,
                    menuId : this.menuId,
                    ...this.listQuery,
                    ...this.searchForm
                }
                request({
                    url: '/api/example/Mt_safe_archives/getList',
                    method: 'post',
                    data: query,
                }).then(res => {
					let _list = this.dataList(res.data);
                    this.mescroll.endSuccess(res.data.list.length);
                    if (page.num == 1) this.list = [];
                    const list = _list.map(o => ({
                        show: false,
                        ...o
                    }));
                    this.list = this.list.concat(_list);
                }).catch(() => {
                    this.mescroll.endErr();
                })
            },
            handleClick(index, index1) {
				const item = this.list[index]
                request({
                    url: '/api/example/Mt_safe_archives/' + item.id,
                    method: 'delete'
                }).then(res => {
                    uni.showToast({
                        title: res.msg,
                        complete: () => {
                            this.$u.toast(res.msg)
                            this.list.splice(index, 1)
							if (!this.list.length) this.mescroll.showEmpty()
                        }
                    })
                })
            },
            open(index) {
                this.list[index].show = true;
                this.list.map((val, idx) => {
                    if (index != idx) this.list[idx].show = false;
                })
            },
            search() {
                if (this.isPreview == '1') return
                this.searchTimer && clearTimeout(this.searchTimer)
                this.searchTimer = setTimeout(() => {
                    this.list = [];
                    this.mescroll.resetUpScroll();
                }, 300)
            },
            goDetail(id, status) {
                let btnType = ''
                let btnList = []
                btnList.push('btn_edit')
                btnList.push('btn_detail')
                if(btnList.includes('btn_detail')){
                    btnType = "btn_detail"
                }
                if(btnList.includes('btn_edit')){
                    btnType = "btn_edit"
                }
                if(!btnType) return
                this.jumPage(id, status,btnType)
            },
            addPage() {
				this.jumPage()
			},
            jumPage(id, status,btnType){
				if (!id && !status) btnType = 'btn_add'
				uni.navigateTo({
                    url: id?'./form?menuId='+this.menuId+'&jurisdictionType='+btnType+'&id=' + id:'./form?menuId='+this.menuId+'&jurisdictionType='+btnType
                })
			},
            cellClick(item) {
                if (this.sortValue === item.value) return
                this.listQuery.sort = item.sort
                this.listQuery.sidx = item.sidx
                this.sortValue = item.value
                this.$refs.uDropdown.close();
                this.$nextTick(() => {
                    this.list = [];
                    this.mescroll.resetUpScroll();
                })
            },
            reset() {
                this.$refs.searchForm.resetFields()
            },
            closeDropdown() {
                this.$refs.uDropdown.close();
                this.$nextTick(() => {
                    this.list = [];
                    this.mescroll.resetUpScroll();
                })
            },
			dataList(data){
				let _list =[]
				for(let i=0;i<data.list.length;i++){
					let _data = data.list[i]
                    _data.gender = JSON.parse(_data.gender)
                    _data.health = JSON.parse(_data.health)
					_list.push(_data)
				}
				return _list;
			},
        },
    }
</script>

<style lang="scss">
    page {
        background-color: #f0f2f6;
        height: 100%;
        /* #ifdef MP-ALIPAY */
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        /* #endif */
    }
</style>
